package com.czk.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/9 11:18
 */
object Spark05_RDD_Operator_Transform_Par {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc = new SparkContext(sparkConf)

    val rdd = sc.makeRDD(List(1, 2, 3, 4), 2)

    val mapRDD=rdd.mapPartitionsWithIndex(
      // index 索引编号
      (index, iter) => {
        // 保留第二个分区的数据
        if (index == 1) {
          iter
          // 返回空迭代器
        } else {
          Nil.iterator
        }
      }
    )
    mapRDD.collect().foreach(println)

  }
}
